//
//  SqlUtil.h
//  NewsReader
//
//  Created by blacksun on 10-10-19.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "sqlite3.h"
#import "Feed.h"
#import "Content.h"

#define kSqlFilePath @"data.sqlite3"


@interface SqlUtil : NSObject {

}

+ (sqlite3 *)openDatabse;
+ (void)createFeedTable;

+ (NSString *) buildSelectFeedSqlWithSection:(NSString *)sectionId from:(long) from to:(long) to;
+ (NSString *) buildSelectFeedSqlWithSubject:(NSString *)subjectId from:(long) from to:(long) to;
+ (NSMutableArray *)selectFeedsWithSql:(NSString *)sql;


+ (NSString *) buildCountFeedSqlWithSection:(NSString *)sectionId from:(long) from to:(long) to;
+ (NSString *) buildCountFeedSqlWithSubject:(NSString *)subjectId from:(long) from to:(long) to;
+ (NSInteger)countFeedsWithSectionId:(NSString *)sql;

+ (NSString *) buildSelectFeedSqlWithSection:(NSString *)sectionId startFeedId:(NSInteger)startFeedId andNeedCount:(NSInteger)count;
+ (NSString *) buildSelectFeedSqlWithSubject:(NSString *)subjectId startFeedId:(NSInteger)startFeedId andNeedCount:(NSInteger)count;


+ (NSString *)buildSelectMaxIndexWithSectionId:(NSString *)sectionId;
+ (NSString *)buildSelectMaxIndexWithSubjectId:(NSString *)subjectId;
+ (NSInteger)selectMaxIndexWithSectionOrSubject:(NSString *)sql;


+ (NSArray *)selectContentsWithFeed:(Feed *)feed;

+(void)saveOrUpdateFeedsAndItsContent:(NSArray *)feeds;

+(void)deleteFeedsAndItsContentsEalierThen:(NSDate *)date;

@end
